<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智慧农业监控系统</title>
    <!-- 引入Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 引入Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <!-- 引入自定义CSS -->
    <link rel="stylesheet" href="/static/css/style.css">
    <!-- 引入Font Awesome图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
    <div class="container-fluid">
        <header class="bg-primary text-white p-3 mb-4">
            <div class="row align-items-center">
                <div class="col">
                    <h1><i class="fas fa-leaf me-2"></i>智慧农业监控系统</h1>
                </div>
                <div class="col-auto">
                    <div id="connection-status" class="badge bg-success">已连接</div>
                </div>
            </div>
        </header>

        <div class="row mb-4">
            <div class="col-md-8">
                <!-- 传感器数据实时监控 -->
                <div class="card shadow-sm mb-4">
                    <div class="card-header bg-light">
                        <h5 class="card-title mb-0">传感器数据实时监控</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-6">
                                <canvas id="temperatureChart"></canvas>
                            </div>
                            <div class="col-md-6">
                                <canvas id="humidityChart"></canvas>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 传感器数据 -->
                <div class="card shadow-sm">
                    <div class="card-header bg-light">
                        <h5 class="card-title mb-0">传感器数据</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-temperature-high text-danger"></i></div>
                                    <div class="sensor-data">
                                        <h6>温度</h6>
                                        <p id="temperature">0 °C</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-tint text-primary"></i></div>
                                    <div class="sensor-data">
                                        <h6>湿度</h6>
                                        <p id="humidity">0 %</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-wind text-info"></i></div>
                                    <div class="sensor-data">
                                        <h6>风速</h6>
                                        <p id="windSpeed">0 m/s</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-sun text-warning"></i></div>
                                    <div class="sensor-data">
                                        <h6>光照</h6>
                                        <p id="lightLux">0 lux</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-seedling text-success"></i></div>
                                    <div class="sensor-data">
                                        <h6>土壤湿度</h6>
                                        <p id="soilHumidity">0 %</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-radiation-alt text-danger"></i></div>
                                    <div class="sensor-data">
                                        <h6>紫外线</h6>
                                        <p id="uv">0</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-lungs text-secondary"></i></div>
                                    <div class="sensor-data">
                                        <h6>空气质量</h6>
                                        <p id="aqi">0</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-3 mb-3">
                                <div class="sensor-card">
                                    <div class="sensor-icon"><i class="fas fa-clock text-primary"></i></div>
                                    <div class="sensor-data">
                                        <h6>最后更新</h6>
                                        <p id="lastUpdate">-</p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- 设备控制 -->
            <div class="col-md-4">
                <div class="card shadow-sm">
                    <div class="card-header bg-light">
                        <h5 class="card-title mb-0">设备控制</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <label class="form-label"><i class="fas fa-tint me-2 text-primary"></i>水泵控制</label>
                            <div class="form-check form-switch">
                                <input class="form-check-input" type="checkbox" id="pumpSwitch">
                                <label class="form-check-label" for="pumpSwitch" id="pumpStatus">关闭</label>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label"><i class="fas fa-fan me-2 text-primary"></i>风扇控制</label>
                            <input type="range" class="form-range" min="0" max="5" step="1" id="fanRange">
                            <div class="d-flex justify-content-between">
                                <span>关闭</span>
                                <span id="fanLevel">0</span>
                                <span>最大</span>
                            </div>
                        </div>
                        <div class="mb-3">
                            <label class="form-label"><i class="fas fa-lightbulb me-2 text-warning"></i>LED灯控制</label>
                            <input type="range" class="form-range" min="0" max="5" step="1" id="ledRange">
                            <div class="d-flex justify-content-between">
                                <span>关闭</span>
                                <span id="ledLevel">0</span>
                                <span>最亮</span>
                            </div>
                        </div>
                        <div class="d-grid gap-2">
                            <button class="btn btn-primary" id="autoControlBtn">
                                <i class="fas fa-robot me-2"></i>启用智能控制
                            </button>
                            <button class="btn btn-outline-secondary" id="manualControlBtn">
                                <i class="fas fa-hand-paper me-2"></i>手动控制
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div class="card shadow-sm">
                    <div class="card-header bg-light">
                        <h5 class="card-title mb-0">系统日志</h5>
                    </div>
                    <div class="card-body">
                        <div class="log-container">
                            <div id="logMessages" class="log-messages"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <footer class="mt-4 p-3 text-center text-muted">
            <p>智慧农业监控系统 &copy; 2025</p>
        </footer>
    </div>

    <!-- 引入Socket.IO -->
    <script src="https://cdn.socket.io/4.6.0/socket.io.min.js"></script>
    <!-- 引入jQuery -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <!-- 引入Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <!-- 引入自定义JS -->
    <script src="/static/js/main.js"></script>
</body>
</html>